<template>
    <div class="code-er">
        <div class="user-code">
            <div class="user-message">
                <div class="user-avatar">
                    <img :src="userInfo.headimgurl" alt="">
                </div>
                <div class="user-level">
                    <div class="top">
                        <img src="~assets/icons/vip1.png" alt="">
                        <span>{{userInfo.name}}</span>
                        <!-- <img src="~assets/icons/woman.png" alt=""> -->
                    </div>
                    <div class="bottom">
                        <span>ID: {{id}}</span>
                    </div>
                </div>
            </div>
            <div class="code-box">
                <div id="qrcode">

                </div>
                <span>扫描上方二维码，进入商城</span>
            </div>
        </div>
        <!-- <div class="share-btns">
            <div class="share">
                <img src="~assets/icons/wechat.png" alt="">
                <span>发送给好友</span>
            </div>
            <div class="share">
                <img src="~assets/icons/firends.png" alt="">
                <span>分享至朋友圈</span>
            </div>
            <div class="share">
                <img src="~assets/icons/download.png" alt="">
                <span>保存到本机</span>
            </div>
        </div> -->
    </div>
</template>

<script>
import QRCode from 'qrcodejs2'

export default {
    name:'codeEr',
    data(){
        return {
            clientHeight:0,
            userInfo:{},
            id:''
        }
    },
    methods:{
        getUserInfo(){
            let that = this;
            let token = localStorage.getItem('token');
            let loader = that.loading();
            that.id = localStorage.getItem('distribution');
            that.$ajax(that, 'get', that.$api.userInfo, null, token, function(res){
                if(res.data['msg']){
                    that.userInfo = res.data.msg;
                }else{
                    that.toast(re.data.msg)
                }
                loader.close();
            })
        },
        qrcode(){
            let distribution = localStorage.getItem('distribution');
            let url = `http://dahua-soft.com/frontend/#/container/home?distributor_id=${distribution}`;
            console.log(url);
            //let url = 'http://'+window.location.host+'?distributor_id='+distribution;
            // let url = 'https://www.baidu.com';
            console.log(url);
            new QRCode('qrcode', {
                width:200,
                height:200,
                text: url
            })
        }
    },
    mounted(){
        let scale = window.devicePixelRatio;
        let clientHeight = document.documentElement.clientHeight;
        this.clientHeight = (scale*clientHeight-88)/100;
        this.$store.state.tab = '二维码';
        this.getUserInfo();
        this.qrcode();
    },
    activated(){
        this.$store.state.tab = '二维码';
    }
}
</script>

<style lang='less'>
@rem:100rem;

.code-er{
    width: 750/@rem;
    margin-top: 88/@rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    .user-code{
        width: 550/@rem;
        height: 700/@rem;
        margin-top: 200/@rem;
        background: #ffffff;
        border-radius: 10/@rem;
    }
    .user-message{
        display: flex;
        margin-top: 30/@rem;
        .user-avatar{
            width: 100/@rem;
            height: 100/@rem;
            margin-left: 30/@rem;
            overflow: hidden;
            border-radius: 10/@rem;
            display: flex;
            align-items: center;
            justify-content: center;
            img{
                height: 200/@rem;
            }
        }
        .user-level{
            margin-left: 30/@rem;
            text-align: start;
            display: flex;
            flex-direction: column;
            justify-content: center;
            .top{
                display: flex;
                align-items: center;
                img:nth-of-type(1){
                    width: 30/@rem;
                    height: 30/@rem;
                }
                img:nth-of-type(2){
                    width: 30/@rem;
                    height: 30/@rem;
                }
                span{
                    margin: 0 20/@rem;
                }
            }
            .bottom{
                font-size: 24/@rem;
                color: #999999;
                margin-top: 10/@rem;
            }
        }
    }
    .code-box{
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        margin-top: 30/@rem;
        img{
            width: 458/@rem;
            height: 458/@rem;
        }
        span{
            font-size: 24/@rem;
            color: #999999;
            margin-top: 35/@rem;
        }
    }
    .share-btns{
        width: 550/@rem;
        height: 160/@rem;
        background: #ffffff;
        display: flex;
        margin-top: 40/@rem;
        .share{
            width: 33.3%;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            img{
                width: 60/@rem;
                height: 60/@rem;
            }
            span{
                font-size: 24/@rem;
                color: #999999;
                margin-top: 10/@rem;
            }
        }
    }
}
</style>
